#makefile for sgu test

include CONFIGME.mak
include filelist.mak

ifneq ($(shell uname | grep -i linux),)
	PLATFORM := LINUX
endif

ifneq ($(shell uname | grep -i freebsd),)
	PLATFORM := FREEBSD
endif

ifneq ($(shell uname | grep -i cygwin),)
	PLATFORM := CYGWIN
endif

ifeq ($(BUILDDIR),)
	BUILDDIR := $(HOME)/tmp
endif

ifeq ($(USERLOCALDDIR),)
	USERLOCALDIR := $(HOME)/local
endif



WARNINGS := \
	-Wall \
	-W \
	-Wpointer-arith \
	-Wcast-qual \
	-Wcast-align \
	-Wwrite-strings \
	-Wconversion \
	-Wsign-compare \
	-Woverloaded-virtual 

CXXFLAGS := --pipe -ffor-scope $(WARNINGS)
LDFLAGS := --pipe
LDLIBS :=
LIBDIR := $(USERLOCALDIR)/lib
TARGET := test
INCDIR := $(USERLOCALDIR)/include

ifeq ($(DEBUGBUILD),1)
	CXXFLAGS += -ggdb
	OBJPREFIX := $(BUILDDIR)/sgu/test/dbg
	SGU := sgu-dbg
else
	CPPFLAGS := -DNDEBUG 
	CXXFLAGS += -O3
	LDFLAGS += -s
	OBJPREFIX := $(BUILDDIR)/sgu/test/rls
	SGU := sgu
endif

LDLIBS += -l$(SGU)

OBJECTS := $(addprefix $(OBJPREFIX)/,$(OBJECTS))
TARGET := $(OBJPREFIX)/$(TARGET)


ifeq ($(PLATFORM),LINUX)
	WARNINGS += -Wshadow
	SUFX := so	
endif

ifeq ($(PLATFORM),FREEBSD)
	SUFX := so	
endif

ifeq ($(PLATFORM),CYGWIN)
	WARNINGS += -Wshadow
	TARGET := $(TARGET).exe
	SUFX := dll	
endif	

SGULIB := $(LIBDIR)/lib$(SGU)
ifeq ($(USESTATIC),1)
	CPPFLAGS += -DSGU_USESTATIC
	SGULIB := $(SGULIB)-static.a
else
	CPPFLAGS += -DSGU_USEDYNAMIC
	SGULIB := $(SGULIB).$(SUFX)
endif


.PHONY: init
.PHONY: clean

$(OBJPREFIX)/%.o : %.cc $(HEADERS)
	$(CXX) -I $(INCDIR) -c $(CPPFLAGS) $(CXXFLAGS) $< -o $@

all: init $(TARGET)
	cp 'u' $(OBJPREFIX) 

$(TARGET): $(SGULIB) $(OBJECTS)
	$(CXX) -L $(LIBDIR) $(LDFLAGS) -o $@ $^ $(LDLIBS)


init:

ifndef PLATFORM
	$(error Unknown platform)
endif
	
	mkdir -p $(OBJPREFIX)

clean:
	$(RM) $(OBJECTS)
	$(RM) $(TARGET)
	$(RM) -r 'tmp'
	
